﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RoardersAgentSim.Map;

namespace RoardersAgentSim.Agent
{
	/// <summary>
	/// Shelter
	/// </summary>
	public class Shelter
	{

		#region properties
		/// <summary>
		/// zone in which shelter is localized
		/// </summary>
        public Zone h_s { get { return Node.Zone;  } }
		/// <summary>
		/// Shelter capacity
		/// </summary>
		public int z { get; set; }
		/// <summary>
		/// for evacuation or for injured people
		/// </summary>
		public int psi { get; set; }
		/// <summary>
		/// Residual capacity
		/// </summary>
		public int zr { get; set; }
		/// <summary>
		/// Shelter ID
		/// </summary>
		public int ShelterID;
        /// <summary>
        /// Calculate how many groups can be sent to this shelter
        /// </summary>
        public int GroupsAvailable
        {
            get
            {
                return (int)Math.Ceiling((double)(z / PopulationManager.GROUPSIZE));
            }
        }

        public bool IsFull
        {
            get
            {
                return this.zr <= 0;
            }
        }

        public Node Node
        {
            get;
            set;
        }

        public ShelterType ShelterType;
		#endregion

        #region log attributes

        public string Description
        {
            get
            {
                return "Shelter " + ShelterID + " (node " + this.Node.NodeID + ")";
            }
        }

        #endregion

        #region export attributes
        /// <summary>
        /// 
        /// </summary>
        public int LastTravelTime
        {
            private set;
            get;
        }

        public int FullTime
        {
            private set;
            get;
        }

        #endregion

        public Shelter()
        {
            FullTime = -1;
            LastTravelTime = -1;
        }

        #region methods
        /// <summary>
		/// Update the residual capacity
		/// </summary>
		/// <param name="new_people"></param>
		public void UpdateResidualCapacity(int new_people)
		{
            LogHelper.LogStep("Update residual capacity "+this.Description+" with "+new_people.ToString());
			this.zr -= new_people;
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="time"></param>
        public void UpdateTravelTime(int time)
        {
            this.LastTravelTime = time;
            if(this.zr<=0)
                this.FullTime = time;
        }

		#endregion

       
    }
    public enum ShelterType
    {
        HOSPITAL,
        SHELTER
    }
}




